/**
 * v-sub 截断
 */

let break_list = [' ']


export default {
  inserted(el, binding, vnode) {
    const {value} = binding
    let enableTab = false;
    let content = el.innerHTML
    let content_list = content.split('')
    let item_index = 0;
    let result = "";
    for (let index = 0; index < content_list.length; index++) {
      let item = content_list[index]
      if (item === "<") {
        enableTab = true;
      }
      if (item === ">") {
        enableTab = false
      }

      if (!enableTab) {
        if (break_list.includes(item)){
          continue
        }
        item_index++
      }
      result += item;
      if (item_index === value){
        break
      }
    }
    el.innerHTML = result;
  }
}

